package com.itcam.lease.web.app.service.impl;

import com.itcam.lease.model.entity.ApartmentInfo;
import com.itcam.lease.model.entity.FacilityInfo;
import com.itcam.lease.model.entity.LabelInfo;
import com.itcam.lease.model.enums.ItemType;
import com.itcam.lease.web.app.mapper.*;
import com.itcam.lease.web.app.service.ApartmentInfoService;
import com.itcam.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.itcam.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;

    @Autowired
    private GraphInfoMapper graphInfoMapper;

    @Autowired
    private LabelInfoMapper labelInfoMapper;

    @Autowired
    private FacilityInfoMapper facilityInfoMapper;

    @Autowired
    private RoomInfoMapper roomInfoMapper;


        /**
     * 根据id获取公寓信息
     *
     * @param id 公寓id
     * @return 公寓详细信息
     */
    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        // 1.查询公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(id);
        // 2.查询图片信息
        List<GraphVo> graphVoList = graphInfoMapper.selectListByItemTypeAndId(ItemType.APARTMENT, id);
        // 3.查询标签信息
        List<LabelInfo> labelInfoList = labelInfoMapper.selectListByApartmentId(id);
        // 4.查询配套信息
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectListByRoomId(id);
        // 5.查询最小租金
        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(id);

        // 创建一个新的 ApartmentDetailVo 对象，用于存储公寓的详细信息
        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();
        // 使用 Spring 的 BeanUtils 工具类将公寓信息对象 apartmentInfo 的属性复制到 apartmentDetailVo 中
        BeanUtils.copyProperties(apartmentInfo, apartmentDetailVo);
        // 将查询到的图片信息列表设置到 apartmentDetailVo 中
        apartmentDetailVo.setGraphVoList(graphVoList);
        // 将查询到的标签信息列表设置到 apartmentDetailVo 中
        apartmentDetailVo.setLabelInfoList(labelInfoList);
        // 将查询到的配套信息列表设置到 apartmentDetailVo 中
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);
        // 将查询到的最小租金设置到 apartmentDetailVo 中
        apartmentDetailVo.setMinRent(minRent);
        // 返回包含公寓详细信息的 apartmentDetailVo 对象
        return apartmentDetailVo;
    }

}




